package com.project.controller;

import com.github.pagehelper.PageInfo;
import com.project.ResultVO;
import com.project.mapper.ClientDto;
import com.project.remote.IClientRemoteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("client")
@Api(tags = "客户测试接口")
public class ClientController {
    @Autowired
    private IClientRemoteService clientRemoteService;
    @GetMapping("findByItem")
    @ApiOperation(value = "按选项分页查找客户")
    public PageInfo<ClientDto> findByItem(int page,
                                          int pageSize,
                                          String name,
                                          String range){
        if (name == null || name.equals("")){
            name = "$";
        }
        if (range == null || range.equals("")){
            range = "$";
        }
        return clientRemoteService.findByItem(page,pageSize,name,range);
    }

    @PostMapping("add")
    @ApiOperation(value = "添加客户")
    public ResultVO add(ClientDto client){
        return clientRemoteService.add(client);
    }

    @GetMapping("findById")
    @ApiOperation(value = "按id查询客户")
    public ClientDto findById(int id){
        return clientRemoteService.findById(id);
    }

    @PutMapping("update")
    @ApiOperation(value = "修改客户信息")
    public ResultVO update(ClientDto client){
        return clientRemoteService.update(client);
    }
}
